﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BasePlatformCommon
{
	public class Equipment : Device
	{
		public bool HasErrorNeedDisp { get; set; }				// 存在需在界面显示的错误（标红）

		public bool HasNoContinueMarkNeedDisp {	get; set; }		// 存在需在界面显示的错误（编号不连续, 标记 "*" ）

		public int brotherCount = 0;							// 等位附属设备数量

		public PInfoData ProductionInfo { get; set; }			// 产品信息

		/*******************************************************************/

		private byte[] replyDataBytes = new byte[256];			// 状态反馈数据 256byte

		// 无参构造函数
		public Equipment()
		{
			deviceType = DeviceType.Equipment;

			this.name = "附属设备";
			if (LanguageOper.available == true)
			{
				this.name = LanguageOper.ReadValue("Chain", "equ.name");
			}
		}

		// 构造函数
		public Equipment(byte[] replyBytes)	: this()
		{
			if (replyBytes != null && replyBytes.Length >= 256)
			{
				Array.Copy(replyBytes, 0, replyDataBytes, 0, 256);
				parseReplyDataBytes();
			}
		}

		// 解析分控状态反馈数据 - 256 byte
		private void parseReplyDataBytes()
		{
		}

		// 拼接提示信息
		public string buildTipMessage()
		{
			/*
			string tip1 = "通信正常";
			string tip2 = "通信异常";
			string tip3 = "通信不良";
			string formatStr = ", 错误灯具 {0} 个, 通信包 {1} / {2}";

			if (LanguageOper.available == true)
			{
				tip1 = LanguageOper.ReadValue("Chain", "sub.commNormal");
				tip2 = LanguageOper.ReadValue("Chain", "sub.commError");
				tip3 = LanguageOper.ReadValue("Chain", "sub.commBad");
				formatStr = LanguageOper.ReadValue("Chain", "sub.formatStr");
			}

			StringBuilder sb = new StringBuilder();

			double ruler = TotalComm == 0 ? 0.0 : ErrorComm * 1.0 / TotalComm;
			if (ruler <= normalPercent)
			{
				sb.Append(tip1);
			}
			else if (ruler > errorPercent)
			{
				sb.Append(tip2);
			}
			else
			{
				sb.Append(tip3);
			}

			sb.Append(String.Format(formatStr, ErrorLampNum, ErrorComm, TotalComm));

			tipMessage = sb.ToString();
			return tipMessage;
			*/

			return "";
		}
	}
}
